package framework;

import java.sql.ResultSet;
import java.sql.SQLException;

import dbmanager.DatabaseObjectManager;

public class FoodItem {
	String name;
	long creationDate;
	String unit;
	boolean approved;

	public FoodItem(String name, String unit, long creationDate,
			boolean approved) {
		super();
		this.name = name;
		this.unit = unit;
		this.creationDate = creationDate;
		this.approved = approved;
	}
	public FoodItem(String name){
		super();
		this.name = name;
	}
	public FoodItem(ResultSet foodItemResultSet) throws SQLException {
		this.name = foodItemResultSet.getString("name");
		this.unit = foodItemResultSet.getString("unit");
		this.creationDate = DatabaseObjectManager
				.stringToDate(foodItemResultSet.getString("creation_date"));
		this.approved = foodItemResultSet.getString("approved").equals("1") ? true
				: false;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(long creationDate) {
		this.creationDate = creationDate;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public boolean isApproved() {
		return approved;
	}

	public void setApproved(boolean approved) {
		this.approved = approved;
	}

	public static void main(String[] args) {

	}

	public String toString() {
		return String.format("| %1$-10s | %2$-10s | %3$-20s | %4$-12s |", name,
				unit, creationDate, approved ? "Approved" : "Not Approved");
	}
}
